using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class QuestGiver_King : MonoBehaviour
{
    private DialogueController dialogueController;
    public QuestData_SO currentQuest;
    public QuestData_SO secondQuest;


    public DialogueData_SO  startDialogue;
    public DialogueData_SO  progressDialogue;
    public DialogueData_SO  completeDialogue;
    public DialogueData_SO  finishedDialogue;

    public AudioClip ending;

    #region 人物状态
    public bool IsStarted
    {
        get
        {
            if (QuestManager.Instance.HaveQuest(currentQuest))
            {
                return QuestManager.Instance.GetTask(currentQuest).IsStarted;
            }
            else return false;
        }
    }
    public bool IsComplete
    {
        get
        {
            if (QuestManager.Instance.HaveQuest(currentQuest))
            {
                return QuestManager.Instance.GetTask(currentQuest).IsComplete;
            }
            else return false;
        }
    }
    public bool IsFinished
    {
        get
        {
            if (QuestManager.Instance.HaveQuest(currentQuest))
            {
                return QuestManager.Instance.GetTask(currentQuest).IsFinished;
            }
            else return false;
        }
    }
    

    #endregion
    
    private void Awake()
    {
        dialogueController = GetComponent<DialogueController>();
    }
    
    
    private void Update()
    {
        if (QuestManager.Instance.GetTask(secondQuest)!=null && QuestManager.Instance.GetTask(currentQuest)!=null)
        {
            if (IsStarted && !QuestManager.Instance.GetTask(secondQuest).IsComplete)
            {
                dialogueController.dialogueDataSo = startDialogue;
            }

            if (IsStarted && QuestManager.Instance.GetTask(secondQuest).IsComplete)
            {
                if (IsComplete)
                {
                    dialogueController.dialogueDataSo = completeDialogue;
                }

            }

            if (IsFinished && QuestManager.Instance.GetTask(secondQuest).IsFinished)
            {
                dialogueController.dialogueDataSo = finishedDialogue;
                AudioManager.Instance.AudioSource.Pause();
                AudioManager.Instance.AudioSource.clip = ending;
                AudioManager.Instance.AudioSource.Play();
            }
        }
    }
}
